package com.stupro.cjlu.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.stupro.cjlu.entity.Admain;
import com.stupro.cjlu.mapper.AdmainMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

//增删查改
@Repository
public class AdmainDAO extends BaseDAO{
    private final AdmainMapper admainMapper;

    public AdmainDAO(AdmainMapper mapper) {
        this.admainMapper = mapper;
    }

    //通过用户名获取数据
    public Admain getByUsername(String adUserName) {
        LambdaQueryWrapper<Admain> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Admain::getAdName, adUserName);
        return admainMapper.selectOne(wrapper);
    }

    //增加数据
    public int insert(Admain admain) {
        return admainMapper.insert(admain);
    }

    //删除数据
    public int delete(Integer adID) {
        return admainMapper.deleteById(adID);
    }

    //查询数据
    public Admain get(Integer adID) {
        return admainMapper.selectById(adID);
    }

    //更新数据
    public int update(Admain admain) {
        return admainMapper.updateById(admain);
    }

    //查询所有数据
    public List<Admain> list() {
        return admainMapper.selectList(new LambdaQueryWrapper<>());
    }
}
